#define _CRT_SECURE_NO_WARNINGS 1

#include"SList.h"

void TestSLT1()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);

	SLTPushBack(&plist, 4);
	SLTPrint(plist);

	SLTPushFront(&plist, 5);
	SLTPrint(plist);
}

void TestSLT2()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);

	SLTPopBack(&plist);
	SLTPrint(plist);

	SLTPopFront(&plist);
	SLTPrint(plist);
}

void TestSLT3()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);

	SLTPrint(SLTInsert(&plist, SLTFind(plist, 2), 6));
}


void TestSLT4()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);

	SLTErase(&plist, SLTFind(plist, 3));
	SLTPrint(plist);
}

void TestSLT5()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);

	SLTDestory(&plist);
	SLTPrint(plist);
}
void TestSLT6()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);
	SLTPrint(plist);
	SListInsertAfter(&plist, 8);
	SLTPrint(plist);
}
void TestSLT7()
{
	SLNode* plist = NULL;
	SLTPushFront(&plist, 1);
	SLTPushFront(&plist, 2);
	SLTPushFront(&plist, 3);

	SLTPrint(plist);

	SListEraseAfter(SLTFind(plist, 1));

	SLTPrint(plist);
}

//
//int main()
//{
//	TestSLT7();
//	return 0;
//}

SLNode* removeElements(SLNode* head, int val)
{
	SLNode* prev = NULL;
	SLNode* cur = head;
	while (cur)
	{
		if (cur->val == val)
		{
			struct ListNode* next = cur->next;
			free(cur);

			if (prev)
				prev->next = next;

			cur = next;
		}
		else
		{
			prev = cur;
			cur = cur->next;
		}
	}
	return head;
}

int main()
{
	SLNode* n1 = (SLNode*)malloc(sizeof(SLNode));
	SLNode* n2 = (SLNode*)malloc(sizeof(SLNode));
	SLNode* n3 = (SLNode*)malloc(sizeof(SLNode));
	SLNode* n4 = (SLNode*)malloc(sizeof(SLNode));
	n1->val = 1;
	n2->val = 6;
	n3->val = 2;
	n4->val = 3;

	n1->next = n2;
	n2->next = n3;
	n3->next = n4;
	n4->next = NULL;

	SLTPrint(n1);
	removeElements(n1, 6);
	SLTPrint(n1);

	return 0;
}